﻿CREATE PROCEDURE [dbo].[yaf_usergroup_save](
                @UserID  INT,
                @GroupID INT,
                @Member  BIT)
AS
    BEGIN
        IF @Member = 0
        DELETE FROM yaf_UserGroup
        WHERE       UserID = @UserID
        AND GroupID = @GroupID
        ELSE
        INSERT INTO yaf_UserGroup
                   (UserID,
                    GroupID)
        SELECT @UserID,
               @GroupID
        WHERE  NOT EXISTS (SELECT 1
                    FROM   yaf_UserGroup
                    WHERE  UserID = @UserID
                    AND GroupID = @GroupID)
    END


